/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.config;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.joda.time.DateTime;
import org.tnmk.worktime.service.PathService;
import org.tnmk.worktime.utils.TimeUtils;

/**
 *
 * @author Administrator
 */
public class AppConfig {

  /**
   * Configured in Version.properties file
   */
  public static final String PROP_BUILD_TIME = "build.time";
  public static final String PROP_BUILD_VERSION = "build.version";
  private static final String FILE_VERSION = "/build.properties";

  public static final String TIME_PATTERN = "dd/MM/yyyy hh:mm:ss a";
  private static final Properties buildProperties = new Properties();

  static{
    loadBuildProperties();
  }
  
  public static String getTitle() {
    DateTime time = DateTime.now();
    String buildTime = getBuildProperty(PROP_BUILD_TIME);
    File parent = PathService.getParentDir();
    return "[" + parent.getName() + "] " + TimeUtils.toString(time, "hh:mm:ss a") + " (build: " + buildTime + ")";
  }

  public static String toString(DateTime dateTime) {
    return TimeUtils.toString(dateTime, TIME_PATTERN);
  }

  public static DateTime toDateTime(String dateTimeString) {
    return TimeUtils.toDateTime(dateTimeString, TIME_PATTERN);
  }

  public static void loadBuildProperties() {
    String rs = null;
    try {
      InputStream stream = AppConfig.class.getClass().getResourceAsStream(FILE_VERSION);
      buildProperties.load(stream);
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
  /**
   * @param property PROP_BUILD_XXX
   * @return 
   */
  public static String getBuildProperty(String property) {
    return buildProperties.getProperty(property);
  }
}
